<?php


namespace Admin\Controller;

use Admin\Model\ManagerModel;
use Think\Controller;
use Think\Verify;

class ManagerController extends Controller
{
    public function login()
    {
//        dump(session('name'));
        if(empty($_POST)){
            $this->display();
        }else{
            $verify_code=new Verify();
            if($verify_code->check($_POST['captcha'])){
                $managerModel=new ManagerModel();
                if ($managerModel->checkNamePwd($_POST['admin_user'],$_POST['admin_pwd'])){
                    session('name',$_POST['admin_user']);
                    session('id',session_id());
                    $this->success('登录成功','/index.php/admin/index/index');//sucess() url需从根开始写，不可直接index/index ，redirect不用
                }else{
                    $this->error('用户名或密码错误');
                }
            }else{
                $this->error('验证码错误');
            }
        }
    }
    public function loginOut(){
        session('name',null);
        session('id',null);
        $this->redirect('login');
    }
    /**
     * 生成验证码
     */
    public function verify()
    {
        $config = [
            'fontSize' => 15,    // 验证码字体大小
            'length' => 4,     // 验证码位数
            'useNoise' => false, // 关闭验证码杂点
            'useCurve' => false, // 关闭验证码杂点
            'imageW' => 100,
            'imageH' => 30,
        ];
        $verify_code = new Verify($config);
        $verify_code->entry();
    }
}